package com.ase.leetcode.二维数组中的查找;

/**
 * @author gyhstart
 * @create 2021/4/27 - 23:44
 **/
public class Solution {
    public static boolean Find(int target, int[][] matrix) {
        if (matrix.length == 0 || matrix[0].length == 0 || matrix == null) {
            return false;
        }
        int row = matrix.length, col = matrix[0].length;
        int r = 0, c = col - 1;
        while (r <= row - 1 && c >= 0) {
            if (target == matrix[r][c]) {
                return true;
            } else if (target < matrix[r][c]) {
                c--;
            } else
                r++;
        }
        return false;
    }

    public static void main(String[] args) {
        int[][] arr = {{1, 4, 7}, {2, 5, 8}, {3, 6, 9}};
        boolean find = Find(10, arr);
        System.out.println("find = " + find);
    }
}
